<!-- 本页数据在61行，state.Cvs -->
<template>
    <el-row>
        <el-col
            :span="17"
            :offset="1"
        >
            <div>
                <h2> {{state.currentInfo.title}}</h2>

                <!-- <div class="time">
                    {{whichTime(currentInfo.editTime)}}
                </div> -->

                <el-divider>
                    <el-icon>
                        <star-filled />
                    </el-icon>
                </el-divider>

                <div v-html="state.currentInfo.content"></div>
            </div>
            <el-button type="primary" @click="handlePost">投递</el-button>
        </el-col>
        <el-col
            :span="4"
            :offset="1"
            :pull="1"
        >
        </el-col>
    </el-row>
    <el-dialog v-model="dialogVisible" title="选择简历" width="50%">
        <el-button v-for="item in state.Cvs" @click="handleChooseCv(item.id)">
            {{ item.title }}
        </el-button>
            
    </el-dialog>
</template>

<script setup>
import { onMounted, ref,watchEffect,onBeforeUnmount,reactive } from "vue";
import { ElMessage } from 'element-plus'
import axios from "axios";
import { useRoute,useRouter } from "vue-router";
import { StarFilled } from "@element-plus/icons-vue";
import { useStore } from 'vuex'

let dialogVisible = ref(false)
const route = useRoute();
const store = useStore();
const router = useRouter();
let state = reactive({
    currentInfo:{
        title:'',
        content:''
    },
    Cvs:[]
})

const handlePost=async()=>{
    const informationId = route.params.id
    //从后端通过ID获取该学生所有简历
    state.Cvs=[
        {
            id: "1",
            title: "cv1",
            job_prefer: 'cv1',
            education_exp: 'cv1',
            project_exp: 'cv1',
            internship: 'cv1',
            price: 'cv1',
            other_advantage: 'cv1',
        },
        {
            id: "2",
            title: "cv2",
            job_prefer: 'cv2',
            education_exp: 'cv2',
            project_exp: 'cv2',
            internship: 'cv2',
            price: 'cv2',
            other_advantage: 'cv2',
        },
        {
            id: "3",
            title: "cv3",
            job_prefer: 'cv3',
            education_exp: 'cv3',
            project_exp: 'cv3',
            internship: 'cv3',
            price: 'cv3',
            other_advantage: 'cv3',
        }
    ]
    ElMessage("正在获取简历数据")
    let cvdata = await axios.get(`/cv/findByAuthor?author=${store.state.userInfo.id}`)
    console.log(cvdata)
    state.Cvs = cvdata.data.data
    ElMessage.success("简历获取成功")
    dialogVisible.value = true
}
const handleChooseCv=async(cvId)=>{
    let form = {
        cv_id:cvId,
        article_id:route.params.id,
        advice:""
    }
    //将记录发送到“投递记录表”
    console.log(form)
    await axios.post("/postRecord/add",form)
    ElMessage.success("投递成功")
    dialogVisible.value = false
}
onMounted(async()=>{
    let id = route.params.id
    console.log(id)
    //通过id从后端获取数据

    state.currentInfo = {
        title:"loading...",
        content:"<h5>loading...</h5>"
    }

    let res = await axios.get(`/article/findById?id=${id}`)
    console.log(res)
    state.currentInfo = res.data.data

})

onBeforeUnmount(()=>{
    stop()
})



</script>

<style scoped lang="scss">
.el-row {
  margin-top: 30px;
}

.time {
  font-size: 13px;
  color: gray;
}
</style>
